package com.ruoyi.luban.controller;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.luban.domain.WXUserLoginInfo;
import com.ruoyi.luban.service.IPWxUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/wxapi")
@Controller
public class WXAPIController extends BaseController {
    @Value("${wx.getOpenId.api}")
    private String getOpenIdApi;
    @Value("${wx.appid}")
    private String appidWX;
    @Value("${wx.key}")
    private String keyWX;
    @Autowired
    WxMaService wxMaService;

    /**
     * 微信服务器验证接口
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "wxToken",method =  {RequestMethod.GET,RequestMethod.POST})
    @Log(title = "微信服务端token请求", businessType = BusinessType.INSERT)
    public void wxToken(HttpServletRequest request , HttpServletResponse response) throws IOException {
        logger.info("微信请求进来了..");
        String echostr = request.getParameter("echostr");
        response.getWriter().println(echostr);
        return;
    }
}